package com.moxiao.yfjh.module.maker.service.matchmakerRecord;

import com.moxiao.yfjh.module.maker.controller.admin.matchmakerRecord.vo.MatchmakerRecordCreateReqVO;
import com.moxiao.yfjh.module.maker.controller.admin.matchmakerRecord.vo.MatchmakerRecordExportReqVO;
import com.moxiao.yfjh.module.maker.controller.admin.matchmakerRecord.vo.MatchmakerRecordPageReqVO;
import com.moxiao.yfjh.module.maker.controller.admin.matchmakerRecord.vo.MatchmakerRecordUpdateReqVO;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import com.moxiao.yfjh.module.maker.controller.admin.matchmakerRecord.vo.*;
import com.moxiao.yfjh.module.maker.dal.dataobject.matchmakerRecord.MatchmakerRecordDO;
import com.moxiao.yfjh.framework.common.pojo.PageResult;

import com.moxiao.yfjh.module.maker.convert.matchmakerRecord.MatchmakerRecordConvert;
import com.moxiao.yfjh.module.maker.dal.mysql.matchmakerRecord.MatchmakerRecordMapper;

import static com.moxiao.yfjh.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.moxiao.yfjh.module.maker.enums.ErrorCodeConstants.*;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.collection.ListUtil;

/**
 * 相亲红娘记录 Service 实现类
 *
 * @author mx
 */
@Service
@Validated
public class MatchmakerRecordServiceImpl implements MatchmakerRecordService {

    @Resource
    private MatchmakerRecordMapper matchmakerRecordMapper;

    @Override
    public Long createMatchmakerRecord(MatchmakerRecordCreateReqVO createReqVO) {
        // 插入
        MatchmakerRecordDO matchmakerRecord = MatchmakerRecordConvert.INSTANCE.convert(createReqVO);
        matchmakerRecordMapper.insert(matchmakerRecord);
        // 返回
        return matchmakerRecord.getId();
    }

    @Override
    public void updateMatchmakerRecord(MatchmakerRecordUpdateReqVO updateReqVO) {
        // 校验存在
        validateMatchmakerRecordExists(updateReqVO.getId());
        // 更新
        MatchmakerRecordDO updateObj = MatchmakerRecordConvert.INSTANCE.convert(updateReqVO);
        matchmakerRecordMapper.updateById(updateObj);
    }

    @Override
    public void deleteMatchmakerRecord(Long id) {
        // 校验存在
        validateMatchmakerRecordExists(id);
        // 删除
        matchmakerRecordMapper.deleteById(id);
    }

    private void validateMatchmakerRecordExists(Long id) {
        if (matchmakerRecordMapper.selectById(id) == null) {
            throw exception(MATCHMAKER_RECORD_NOT_EXISTS);
        }
    }

    @Override
    public MatchmakerRecordDO getMatchmakerRecord(Long id) {
        return matchmakerRecordMapper.selectById(id);
    }

    @Override
    public List<MatchmakerRecordDO> getMatchmakerRecordList(Collection<Long> ids) {
        if (CollUtil.isEmpty(ids)) {
            return ListUtil.empty();
        }
        return matchmakerRecordMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<MatchmakerRecordDO> getMatchmakerRecordPage(MatchmakerRecordPageReqVO pageReqVO) {
        return matchmakerRecordMapper.selectPage(pageReqVO);
    }

    @Override
    public List<MatchmakerRecordDO> getMatchmakerRecordList(MatchmakerRecordExportReqVO exportReqVO) {
        return matchmakerRecordMapper.selectList(exportReqVO);
    }

    @Override
    public Long selectMatchmakerRecordByMemberId(Long memberId) {
        return matchmakerRecordMapper.selectMatchmakerRecordByMemberId(memberId);
    }

}
